import { onMounted } from 'vue'
import Dict from './Dict'
import { mergeOptions } from './DictOptions'

export function useDict(options: { dicts?: string[]; [key: string]: any }) {
  const { dicts, ...opts } = options
  mergeOptions(opts)
  if (dicts === undefined || dicts === null) {
    return {
      dict: {} as any,
    }
  }
  const dict: any = new Dict()
  onMounted(() => {
    dict.init(dicts)
  })

  return { dict }
}
